home *** CD-ROM | disk | FTP | other *** search
/ Chip 1996 October / CHIP Ekim 1996.iso / winbatch / exitwin.wb_ < prev    next >
Text File  |  1995-10-31  |  4KB  |  88 lines

  1. ; EXITWIN.WBT  --  Author: Richard Merit
  2.  
  3. ; Places an "Exit Windows" button in the lower right corner of the screen,
  4. ; and makes this button the only possible way of exiting Windows.
  5.  
  6. ; --------------------------------------------------------------------------
  7.  
  8. ; If we're being called with a command-line parameter, we're the second
  9. ; instance of ourself (recursion).  Go down to the label marked "activate".
  10. If param0 != 0 Then Goto activate
  11.  
  12. ; Otherwise, we're just starting out.  So hide the WinBatch icon.
  13. WinHide("")
  14.  
  15. ; Refuse to allow ourself to be terminated, and refuse to allow the user to
  16. ; exit Windows in any manner other than pressing our "Exit Windows" button.
  17. IntControl(12, 10, "Use Exit Windows Button to Exit", 0, 0)
  18.  
  19. ; Define the dialog format.  It's just a single pushbutton in a tiny window.
  20. ; This dialog box is designed to appear in the lower right-hand corner of
  21. ; the screen if you are using the standard Windows VGA driver, and will also
  22. ; be correct for some OEM drivers using large (8514) fonts.  If the dialog
  23. ; box does not appear in the correct location on your screen, you should
  24. ; adjust the "ExitX" and "ExitY" coordinates below accordingly (of course,
  25. ; you can change them to make the dialog appear in any location you desire).
  26. ; If you make these numbers too high, so the dialog box would be completely
  27. ; off-screen, WinBatch may override them and display the dialog box in the
  28. ; center of the screen.  If this happens, make the numbers a little smaller.
  29. ExitFormat = `WWWDLGED,4.0`
  30. ExitCaption = `Exit Windows`
  31. ExitX = 274
  32. ExitY = 225
  33. ExitWidth = 45
  34. ExitHeight = 14
  35. ExitNumControls = 1
  36. Exit01 = `1, 1, 43, DEFAULT, PUSHBUTTON, DEFAULT, "Now!", 1`
  37.  
  38. ; Parse the name of the currently-executing WBT file from our window title
  39. ; (eg, "WBT - EXITWIN.WBT") as follows: search backwards for the first space
  40. ; from the end of the window title, start with the next character, and
  41. ; extract everything down to the end of the title string.
  42. wbtwin = WinName()
  43. space = StrIndex(wbtwin, " ", 0, @BACKSCAN)
  44. wbt = StrSub(wbtwin, space + 1, StrLen(wbtwin) - space)
  45.  
  46. ; Get the name of the currently-active window, so that we can restore the
  47. ; focus to it later on.  "Double up" any quotes, apostrophes, or back quotes
  48. ; embedded in the window title, so that they won't be treated as delimiters.
  49. activewin = WinGetActive()
  50. activewin = StrReplace(activewin, "'", "''")
  51. activewin = StrReplace(activewin, "`", "``")
  52. activewin = StrReplace(activewin, `"`, `""`)
  53.  
  54. ; Run ourself, passing the active window title as a command-line parameter.
  55. ; By placing an extra pair of delimiters around the window title, we force
  56. ; the second copy of WinBatch to treat it as a single parameter, even if it
  57. ; contains spaces (normally, it would get parsed as param1, param2, etc.).
  58. :launch
  59. wbtx=FileNameShort(wbt)
  60. If strupper(FileExtension(wbt)) == "EXE" RunHide(wbtx, "`%activewin%`")
  61. Else RunHide(WinExeName(""), "%wbtx% `%activewin%`")
  62. endif
  63.  
  64. ; Display the dialog.  Wait for the user to press the (only) pushbutton.
  65. Dialog("Exit")
  66.  
  67. ; One last chance for the user to change his or her mind after clicking on
  68. ; the Exit button.  Comment this line out if you don't want this safety net.
  69. If AskYesNo("Exit Windows", "Are you sure?") == @NO Then Goto launch
  70.  
  71. ; Do it.
  72. EndSession()
  73.  
  74. ; If we got here, it means that the Windows session didn't end.  Either
  75. ; there was a DOS window open, or there was a Windows application with
  76. ; unsaved data and the user selected "Cancel" at the "Save file?" prompt.
  77. :cancel
  78. Goto launch
  79.  
  80. :activate
  81.  
  82. ; Give the first instance of WinBatch a chance to display the dialog.
  83. Yield
  84.  
  85. ; Now take the focus away from our dialog box by activating whichever window
  86. ; had previously been active (assuming it's still there).
  87. If WinExist(param1) Then WinActivate(param1)
  88.